

	
	function TweenNano ( p_target, p_duration, p_vars, p_cadency )
	{
		
		var _public = this;
		
		
		// private
		
		_public._cadency		= 100;
		_public._time 			= 0;

		
		// public 
		
		_public.duration 		= p_duration;
		_public.vars 			= new Object();
		_public.startTime 		= 0;
		_public.target			= new Object();
		_public.active			= false;
		_public.gc				= false;
		_public.useFrames		= false;
		_public.ratio			= 0;
		
		// protected
		
		_public._ease			= _public.defaultEaseOut;
		_public._propTweens		= new Array();
		
		_public.reservedProperties = ["ease","delay","useFrames","overwrite","onComplete","onCompleteParams","runBackwards","immediateRender","onUpdate","onUpdateParams"];
			
		
		
		
				
		_public._construct 		= function( p_target, p_duration, p_vars, p_cadency )
		{
			
			p_target.tweenId = "tween_"+TweenNano._tweenIds++;
			
			if( TweenNano._masterList[ p_target.tweenId ] )
			{
				TweenNano._masterList[ p_target.tweenId ].complete(false);
			}
			
			
			
			TweenNano._masterList[ p_target.tweenId ] = this;
			
			
			_public._time = new Date().getTime();
			
			_public.vars = p_vars;
			_public.duration = p_duration;
			_public.target = p_target;
			
			_public._ease = ( typeof( _public.vars.ease ) == "function" ) ? _public.vars.ease : _public.defaultEaseOut;
			_public._cadency = ( p_cadency == undefined ) ? 100 : p_cadency;
			
			_public._propTweens = new Array();
			
			_public.useFrames = false;
			_public.delay = ( typeof( _public.vars.delay ) == "undefined" ) ? 0 : new Number( _public.vars.delay );
			
			
			
			_public.startTime = _public._time + _public.delay;
			_public.renderTime(0);
			
			_public.init();
			
			FrameManager.getInstance().addFrameListener( _public.update, _public );
			
		};
		
		
		_public.defaultEaseOut 	= function( p_t, p_b, p_c, p_d )
		{
			return ( -1 * ( p_t /= p_d ) * ( p_t - 2 ) );
		};	
		
		
		_public.renderTime 		= function( p_time )
		{
			
			var l_prop = new Array();
			var i = _public._propTweens.length;
			
			
			
			
			
			if ( p_time >= _public.duration ) 
			{
				p_time = _public.duration;
				_public.ratio = 1;
			} 
			else if ( p_time <= 0 ) 
			{
				_public.ratio = 0;
			} 
			else 
			{
				_public.ratio = _public._ease( p_time, 0, 1, _public.duration );			
			}
			
			while (--i > -1) 
			{
				l_prop = _public._propTweens[i];
				_public.target[ l_prop[0] ] = l_prop[1] + ( _public.ratio * l_prop[2] ); 
				
				//alert( _public.target[ l_prop[0] ]+", "+_public.ratio+","+l_prop[0]+","+l_prop[1]+","+l_prop[2] );
			}
			
			
			if (typeof(_public.vars.onUpdate) == "function") 
			{
				_public.vars.onUpdate.apply( _public.target, _public.vars.onUpdateParams );
			}
			
			if ( p_time >= _public.duration && !_public.gc ) 
			{
				_public.complete(true);
			}
			
		};
		
		
		_public.init 			= function()
		{
			
			var l_prop;
			var i = 0;
			for ( l_prop in _public.vars) 
			{
				if( _public.reservedProperties.indexOf(l_prop) == -1 )
				{
					_public._propTweens[i] = [l_prop, _public.target[l_prop], new Number( _public.vars[l_prop] - _public.target[l_prop] ) ];
					
					i++;
				}
			}
			
		};
		
		
		_public.complete 		= function( p_complete )
		{		
		
			if ( p_complete && !_public.gc ) 
			{
				_public.gc = true;
				_public.renderTime( _public.duration );
			}
			
			_public.kill();
		
			
			if (_public.vars.onComplete) 
			{
				_public.vars.onComplete.apply( null, _public.vars.onCompleteParams );
			}
		};
			
		
		_public.kill 			= function() 
		{
			delete TweenNano._masterList[ _public.target.tweenId ];
			_public.gc = true;
			
			FrameManager.getInstance().removeFrameListener( _public.update, _public );
		};
		
		
		_public.update 			= function()
		{
			_public._time = new Date().getTime();
			_public.renderTime( _public._time - _public.startTime);
		};
			
			
		
		
		_public._construct( p_target, p_duration, p_vars, p_cadency );
		
		
	}

	

	
	

		
	// static
		
	TweenNano._masterList 				= new Array();
	TweenNano._tweenIds					= 0;
		
	/* static methods */
	
	TweenNano.kill = function( p_target, p_complete )
	{
		p_complete = ( p_complete == true ) ? true : false;
		if( TweenNano._masterList[ p_target.tweenId ] )
		{
			TweenNano._masterList[ p_target.tweenId ].complete( p_complete );
		}
	};
	
	TweenNano.killAll = function( p_target, p_complete )
	{
		var id = "";
		p_complete = ( p_complete == true ) ? true : false;
		
		for( id in TweenNano._masterList )
		{
			TweenNano._masterList[ id ].complete( p_complete );
		}
	};
	
	
	TweenNano.to = function( p_target, p_duration , p_vars, p_cadency ) 
	{
		return new TweenNano( p_target, p_duration, p_vars, p_cadency );
	};
	
	TweenNano.delayer = function( p_delay, p_target, p_duration, p_vars, p_cadency )
	{
		setTimeout( function()
		{
			TweenNano.to( p_target, p_duration, p_vars, p_cadency );
		}, p_delay );
	};
	
		
	TweenNano.delayedCall = function( p_delay, p_onComplete, p_onCompleteParams, p_useFrames )
	{
		return new TweenNano( p_onComplete, 0, { delay: p_delay, onComplete: p_onComplete, onCompleteParams: p_onCompleteParams, useFrames: p_useFrames, overwrite:false } );
	};
	
	